home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / graphics conversion / Sweetheart 1.1 / sweetheart11.exe / src / gcc-pilot / greyscale.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-03  |  2.9 KB  |  91 lines

  1. #pragma pack(2)
  2.    
  3. #include <Common.h>
  4. #include <System/SysAll.h>
  5. #include <UI/UIAll.h>
  6. // from an article by
  7. // Edward Keyes, Daggerware, mistered@1stresource.com
  8. // in PDA Developers 4.6, Nov/Dec 96
  9. void GraySwitchDisplayMode
  10. (short int mode, unsigned char **displayaddr)
  11. // This performs all the register accesses to switch
  12. // between grayscale and black and white modes.
  13. // The displayaddr variable is used in the following way:
  14. // on calling this procedure, load displayaddr with a
  15. // pointer to the address of the new display starting
  16. // address. The function will return a pointer to the
  17. // old address in the same way. The calling procedure is
  18. // responsible for saving and then giving back the old
  19. // black and white display starting address.
  20. // (mode=1 is switch to grayscale, mode=0 is switch to
  21. // black and white)
  22. {
  23. ULong *SSA;
  24. unsigned char *VPW,*PICF,*FRCM,*LBAR,*CKCON;
  25. unsigned char *oldstart;
  26. SSA=(ULong *)0xFFFFFA00;
  27. VPW=(unsigned char *)0xFFFFFA05;
  28. PICF=(unsigned char *)0xFFFFFA20;
  29. FRCM=(unsigned char *)0xFFFFFA31;
  30. LBAR=(unsigned char *)0xFFFFFA29;
  31. CKCON=(unsigned char *)0xFFFFFA27;
  32. if (mode==1) { //switch to grayscale
  33. // save old display starting address
  34. oldstart=(unsigned char *)*SSA;
  35. //switch off LCD update temporarily
  36. *CKCON=*CKCON & 0x7F;
  37. //set new display starting address
  38. *SSA=(ULong)*displayaddr;
  39. //virtual page width now 40 bytes (160 pixels)
  40. *VPW=20;
  41. *PICF=*PICF | 0x01; //switch to grayscale mode
  42. *LBAR=20; //line buffer now 40 bytes
  43. //register to control grayscale pixel oscillations
  44. *FRCM=0xB9;
  45. //let the LCD get to a new frame (20ms delay)
  46. SysTaskDelay(2);
  47. //switch LCD back on in new mode
  48. *CKCON=*CKCON | 0x80;
  49. //return original display address for switch back
  50. *displayaddr=oldstart;
  51. }
  52. else if (mode==0) { //switch to black and white
  53. //save old display starting address
  54. oldstart=(unsigned char *)*SSA;
  55. //switch off LCD update temporarily
  56. *CKCON=*CKCON & 0x7F;
  57. //set new display starting address
  58. *SSA=(ULong)*displayaddr;
  59. //virtual page width now 20 bytes (160 pixels)
  60. *VPW=10;
  61. *PICF=*PICF & 0xFE; //switch to black and white mode
  62. *LBAR=10; // line buffer now 20 bytes
  63. //let the LCD get to a new frame (20ms delay)
  64. SysTaskDelay(2);
  65. //switch LCD back on in new mode
  66. *CKCON=*CKCON | 0x80;
  67. //return original display address for switch back
  68. *displayaddr=oldstart;
  69. }
  70. }
  71.  
  72.  
  73. void GraySetPalette
  74. (short int gray0, short int gray1, short int gray2,
  75. short int gray3)
  76. // This sets the palette of the 4 active shades of gray
  77. // out of a selection of 7. The four parameters represent
  78. // the shades of the 00, 01, 10, and 11 bit patterns,
  79. // respectively. The palette of 7 is as follows, in
  80. // terms of darkness density:
  81. // 0=0/16, 1=4/16, 2=5/16, 3=8/16, 4=11/16, 5=12/16,
  82. // 6=16/16, and 7=16/16. There are two active bit values
  83. // for solid black; either will work.
  84. {
  85. Word *GPMR;
  86. Word temp;
  87. GPMR=(Word *)0xFFFFFA32;
  88. *GPMR=gray2 + (gray3<<4) + (gray0<<8) + (gray1<<12);
  89. }
  90.  
  91.